<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>建议使用学习帮APP</title>
    <script>
        let userInfo = localStorage.getItem('XGB-user')
        if(userInfo === null || JSON.parse(userInfo).id === 0){
            window.location.replace('https://xinguanbang.gitee.io/xinguanbang3.0/pages/login/login.html')
        }
    </script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        html,body{
            height: 100%;
        }
        ul li{
            list-style: none;
        }
        a{
            text-decoration: none;
            
        }
        a:link{
            color: #404040;
        }
        a:visited{
            color: #404040;
        }
        a:hover{
            color: #404040;
        }
        a:active{
            color: #404040;
        }
        ::-webkit-scrollbar{
            /* width: 0; 移动端取消滚动条无效*/
            display: none;
        }
        body{
            background: #f4f4f4;/*#2493f1*/
            display: flex;
            flex-direction: column;
            font-family: 微软雅黑;
            font-size: .3865rem;
            letter-spacing: .0169rem;
            position: relative;
            overflow: hidden;/*禁止上下滑动*/
            -webkit-user-select:none;
            -moz-user-select:none;
            -ms-user-select:none;
            user-select:none;
        }
        
        section{/*
            border: 1px solid red;*/
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            overflow: scroll;
        }
        .container{
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
            box-sizing: border-box;
            padding-bottom: 1.2077rem;
        }
        .container span.title{
            /*
            border: 1px solid red;*/
            width: 90%;
            font-size: .4348rem;
            font-weight: 550;
            margin: .3623rem 0;
        }
        
        .ul{
            /*
            border: 1px solid red;*/
            width: 90%;
            margin-bottom: .4831rem;
        }
        .ul li{
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .ul span.className, .ul span.result{
            width: 100%;
            display: flex;
            flex-direction: row;
            justify-content: left;
            font-size: .3865rem;
            margin-bottom: .2415rem;
        }
        li textarea{
            box-sizing: border-box;
            border-radius: .1208rem;
            width: 100%;
            margin: .2415rem 5%;
            padding: .2415rem;
            color: #b9bec7;
            background: #282c34;
            font-size: .3623rem;
        }
        .imgBox{
            width: 100%;
        }
        .imgBox img{
            width: 100%;
            margin-bottom: .2415rem;
        }
        li button{
            width: 100%;
            height: .9662rem;
            background: #2493f1;
            color: #fff;
            font-size: .3865rem;
            letter-spacing: .0169rem;
            border: none;
            border-radius: .1208rem;
            margin: .4831rem 0;
        }








        


        
    </style>
    <link rel="stylesheet" href="../../../../../css/header.css">
    <link rel="stylesheet" href="../../../../../css/alert.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.2/lib/index.css" />
    
    <script src="../../../../../lib/jquery.min.js"></script>
    <script src="../../../../../lib/vue.js"></script>
    
</head>
<body>
    <header>
        <div class="backBtn"></div>
        <div class="left"></div>
        <span class="title">实验二-基本SQL语句使用与编程连接SQLServer数据库</span>
    </header>
    <script>
        document.querySelector(".backBtn").onclick=function(){
            window.history.go(-1)
        }
    </script>
    <section>
        <div class="container">
            
            <ul class="ul" style="margin-top: .3623rem;">
                
                <span class="result">实现原理与说明</span>
                <div class="imgBox">
                    <p class="t text1">
                        实现原理：<br>&emsp;&emsp;
                        java代码通过eclipse的数据库jdbc驱动插件实现和计算机本地SQLServer数据库的连接。
                        <br>
                        <br>
                        说明：<br>&emsp;&emsp;
                        SQLServer数据库，创建的账户和密码以及数据库配置管理器的端口、数据库名称、数据库表格名称等参数应保持对应。代码中的这些参数根据个人情况进行替换。代码注释可移除或更改，以便理解。
                    </p>
                </div>

                <span class="result" style="margin-top: .3623rem;">项目结构</span>
                <div class="imgBox">
                    <img src="./img/xmjg.png" alt="">
                </div>
                
            </ul>
            
            <span class="title">
                1、新建servlet，命名为connect。
            </span>
            <ul class="ul ul1">
                <li>
                    <span class="className">connect.java</span>
                    <textarea name="" class="txt1" cols="30" rows="10"></textarea>

                    <button id="txt1" onclick="copy(event)">一键复制</button>
                    <span class="result">运行结果</span>
                    <div class="imgBox">
                        <img src="./img/1.png" alt="">
                    </div>
                </li>
                
           </ul>
           





           
        </div>
          
        
            
        
    </section>


    

    <script>
        function readTxt(t, el) {
            $.get(`https://mp-e8e2bde5-0c0c-4622-87b5-66f8b08c3856.cdn.bspapp.com/code/work/sjkjsa_2023/test2/${t}.txt`,function(data) { 
                document.querySelector(el).value=data
            });
        }
        readTxt('connect.java', '.txt1')
    </script>
    <script>
        function copy(e) {
            console.log(e.target.id)
            var element = document.querySelector("."+e.target.id);
            var copyBtn = document.getElementById(e.target.id);
            element.select();
            element.setSelectionRange(0, element.value.length);
            document.execCommand('copy');
            copyBtn.style.background='#c0c0c0'
            copyBtn.innerHTML='已复制'
            setTimeout(function(){
                copyBtn.style.background='#2493f1'
                copyBtn.innerHTML='一键复制'
            },2000)
        }
    </script>
    <!-- 引入vant.js -->
    <script src="https://cdn.jsdelivr.net/npm/vant@2.2/lib/vant.min.js"></script>

    <script>
        new Vue({
            el: 'section',
            data: {
            },
            methods: {
            },
            mounted() {
                /**/
                let userInfo = localStorage.getItem('XGB-user')
                let userid = JSON.parse(userInfo).id
                fetch(`https://fc-mp-e8e2bde5-0c0c-4622-87b5-66f8b08c3856.next.bspapp.com/getUserList/getHmwkVisit_records?test=test2&userid=${userid}`)
                .then(res => res.json())
                .then(res => {
                    this.alertShow = true
                    if(res.state.code === 0){
                        this.$dialog.alert({
                            message: `当前资源已有${res.state.data.users}名用户共计${res.state.data.visit}次访问记录。建议个性化修改代码片段，避免作业雷同。`
                          }).then(() => {
                            // on close
                          });
                    }else{
                        
                    }
                })
            }
        })
    </script>
    <script>
        //根据设备宽度计算html的font-size
        function resetHtmlFont(){
            //获取html对象并动态设置font-size = 设备宽度的1/10
            document.documentElement.style.fontSize = screen.width/10 + 'px';
        }
        //执行一下
        resetHtmlFont();
        //如果窗口大小改变了，则重新计算基础font-size
        window.onresize = resetHtmlFont;
    </script>
</body>
</html>